//
//  PISocket.h
//  sdk
//
//  Created by 城门虾米 on 2019/5/9.
//  Copyright © 2019 虾米城门. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "PNPacket.h"



NS_ASSUME_NONNULL_BEGIN


@protocol PNSocketDelegate;
@interface PNSocket : NSObject

- (id)initWithDelegate:(nullable id<PNSocketDelegate>)delegate delegateQueue:(dispatch_queue_t)delegateQueue;


- (BOOL)connectToHost:(NSString *)host
               onPort:(uint16_t)port
          withTimeout:(int)timeout
                error:(NSError **)errPtr;

- (void)writeData:(NSData *) data;

- (void)sendMessageWithPacketID:(int32_t)packetID msgID:(int16_t)msgID data:(NSDictionary*)data;
- (void)sendStreamWithStreamType:(int8_t)streamType streamData:(NSData*)streamData;
- (void)disconnect;


@end

@protocol PNSocketDelegate <NSObject>
@optional

- (void)socketDidConnect:(PNSocket *)sock;
- (void)socketDidDisconnect:(PNSocket *)sock withError:(nullable NSError *)err;

- (void)socket:(PNSocket *)sock didReadPacket:(PNPacket *)packet;


@end


NS_ASSUME_NONNULL_END
